package model;

import java.util.ArrayList;
import java.util.Scanner;

import service.Constan;
import service.EmployeeAPI;
import service.implement.EmployeeDAO;

public class Employee {
	private int id;
	private String name;
	private String username;
	private String email;
	public Employee(){

	}
	public Employee(int id, String name, String username, String email) {
		super();
		this.id = id;
		this.name = name;
		this.username = username;
		this.email = email;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}

	public Employee inputEmployee() {
		EmployeeAPI ts=new EmployeeDAO();
		Scanner input=new Scanner(System.in);
		System.out.println("----Employee------");
		System.out.println("Enter Name:");
		String name=input.nextLine();
		while(name.trim().equalsIgnoreCase("")){
			System.out.println("Name chua duoc nhap.Nhap lai!");
			name=input.nextLine();
		}
		System.out.println("Enter Username:");
		String username=input.nextLine();
		while(username.trim().equalsIgnoreCase("")){
			System.out.println("Username chua duoc nhap.Nhap lai!");
			username=input.nextLine();
		}
		System.out.println("Enter Email:");
		String email=input.nextLine();
		while(email.trim().equalsIgnoreCase("")){
			System.out.println("Email chua duoc nhap.Nhap lai!");
			email=input.nextLine();
		}
		if(!Constan.isValidEmailAddress(email)){
			System.out.println("Email khong dung dinh dang.Nhap lai!");
			email=input.nextLine();
		}
		Employee emp=new Employee(id,name,username,email);
		return emp;
	}
	public Employee updateEmployee() {
		EmployeeAPI dao=new EmployeeDAO();
		Scanner ip=new Scanner(System.in);
		System.out.println("Enter your ID you want to update: ");
		int id=Integer.parseInt(ip.nextLine());
		if(dao.getEmployeeById(id)==null){
			System.out.println("Id khong ton tai");
			return null;}
		else{
			System.out.println("Thong tin id hien co: ");
			System.out.println(Constan.DISPLAY_EMP);
			Employee em=dao.getEmployeeById(id);
			System.out.println(em);
		}
		System.out.println("Enter name you want update:");
		String name=ip.nextLine();
		while(name.trim().equalsIgnoreCase("")){
			System.out.println("Chua nhap name.Vui long nhap lai!");
			name=ip.nextLine();
		}
		System.out.println("Enter username you want update:");
		String username=ip.nextLine();
		while(username.trim().equalsIgnoreCase("")){
			System.out.println("Username chua duoc nhap");
			username=ip.nextLine();
		}
		System.out.println("Enter email you want update:");
		String email=ip.nextLine();
		while(email.trim().equalsIgnoreCase("")){
			System.out.println("Email chua duoc nhap");
			email=ip.nextLine();
		}
		if(!Constan.isValidEmailAddress(email)){
			System.out.println("Email khong dung dinh dang.Nhap lai!");
			email=ip.nextLine();
		}
		Employee emp=new Employee(id,name,username,email);
		return emp;
	}
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return	"|"+getId() + "\t\t|" + getName() + "\t\t|" + getUsername() + "\t\t\t|" + getEmail();
	}
	



}
